package com.dc.system.controller;

import com.dc.common.model.BaseModel;
import com.dc.system.model.SysRole;
import com.dc.system.service.SysRoleService;
import com.github.pagehelper.PageInfo;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: SysRoleController
 * @Author: ChenXueLi
 * @Date: 2018-05-06 19:00
 */
@Controller
@RequestMapping("/system/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation(value = "添加角色", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "角色名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = false, paramType = "query")
    })
    @RequestMapping("/addSysRole")
    @ResponseBody
    public BaseModel addSysRole(SysRole sysRole, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysRoleService.addSysRole(sysRole,baseModel,request);
    }

    @ApiOperation(value = "删除", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id", value = "角色id", required = true, paramType = "query")
    })
    @RequestMapping("/deleteSysRoleById")
    @ResponseBody
    public BaseModel deleteSysRoleById(SysRole sysRole, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysRoleService.deleteSysRoleById(sysRole,baseModel,request);
    }

    @ApiOperation(value = "查询单个角色", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id", value = "角色id", required = true, paramType = "query")
    })
    @RequestMapping("/getSysRoleById")
    @ResponseBody
    public BaseModel getSysRoleById(SysRole sysRole, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysRoleService.getSysRoleById(sysRole,baseModel,request);
    }

    @ApiOperation(value = "修改一个角色信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id", value = "角色id", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "角色名称", required = false, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = false, paramType = "query")
    })
    @RequestMapping("/updateSysRoleById")
    @ResponseBody
    public BaseModel updateSysRoleById(SysRole sysRole, BaseModel baseModel, HttpServletRequest request) throws Exception{
        return sysRoleService.updateSysRoleById(sysRole,baseModel,request);
    }

    @ApiOperation(value = "分页查询角色", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前查询页数（不填写则为首页）", required = false, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量（默认为10条每页）", required = false, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "角色名称", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_user_id", value = "创建用户id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_user_name", value = "创建用户名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_time_start", value = "创建时间开始标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "create_time_end", value = "创建时间结束标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_user_id", value = "更新用户id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_user_name", value = "更新用户名", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_time_start", value = "更新时间开始标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "update_time_end", value = "更新时间结束标记", required = false, paramType = "query"),
            @ApiImplicitParam(name = "organ_id", value = "单位id", required = false, paramType = "query"),
            @ApiImplicitParam(name = "getByPage", value = "是否需要分页查询（只要有值就不是分页查询）", required = false, paramType = "query")
    })
    @RequestMapping("/getSysRoles")
    @ResponseBody
    public BaseModel getSysRoles(PageInfo<?> pageInfo, SysRole sysRole, BaseModel baseModel, HttpServletRequest request) throws Exception {
        return sysRoleService.getSysRoles(pageInfo,sysRole,baseModel,request);
    }

}
